package com.example.starseas_phone.Adapters;

import android.content.Context;
import android.graphics.drawable.Drawable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.example.starseas_phone.Entity.Apply;
import com.example.starseas_phone.R;

import java.util.List;

public class Applyrecord_TealistviewAdapter extends ArrayAdapter<Apply> {

    private int id;
    private Context mcontext;

    public Applyrecord_TealistviewAdapter(@NonNull Context context, int resource, @NonNull List<Apply> objects) {
        super(context, resource, objects);
        id = resource;
        mcontext = context;
    }

    @NonNull
    @Override
    public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent) {
        Apply apply = getItem(position);
        View view = LayoutInflater.from(parent.getContext()).inflate(id,parent,false);
        TextView applyrecord_tea_listview_ApplicationType = (TextView) view.findViewById(R.id.applyrecord_tea_listview_ApplicationType);
        ImageView applyrecord_tea_listview_Status = (ImageView) view.findViewById(R.id.applyrecord_tea_listview_Status);
        TextView applyrecord_tea_listview_ByTheTime = (TextView) view.findViewById(R.id.applyrecord_tea_listview_ByTheTime);

        switch (apply.getApplicationType()){
            case 1:
                applyrecord_tea_listview_ApplicationType.setText("添加学生信息");
                break;
            case 2:
                applyrecord_tea_listview_ApplicationType.setText("修改学生信息");
                break;
            case 3:
                applyrecord_tea_listview_ApplicationType.setText("修改老师信息");
                break;
            case 4:
                applyrecord_tea_listview_ApplicationType.setText("调课");
                break;
            case 5:
                applyrecord_tea_listview_ApplicationType.setText("成绩录入信息");
                break;
            case 6:
                applyrecord_tea_listview_ApplicationType.setText("修改成绩信息");
                break;
        }
        Drawable drawable1 = mcontext.getResources().getDrawable(R.drawable.wcl);
        Drawable drawable2 = mcontext.getResources().getDrawable(R.drawable.ytg);
        Drawable drawable3 = mcontext.getResources().getDrawable(R.drawable.yqx);
        if (apply.getStatus()==2){
            applyrecord_tea_listview_Status.setImageDrawable(drawable1);
        }else if (apply.getStatus()==4){
            applyrecord_tea_listview_Status.setImageDrawable(drawable2);
        }else if (apply.getStatus()==5){
            applyrecord_tea_listview_Status.setImageDrawable(drawable3);
        }
        String days = apply.getByTheTime();
        days =days.substring(0,10);
        applyrecord_tea_listview_ByTheTime.setText(days);

        return view;
    }
}
